def f(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True

def nearest_prime(words):
    a = {'zero': 0, 'one': 1, 'two': 2, 'three': 3,
            'four': 4, 'five': 5, 'six': 6, 'seven': 7,
            'eight': 8, 'nine': 9}

    if len(words) != 3:
        print("wrong input")
        return
    num = a.get(words[0], -1) * 100 + a.get(words[1], -1) * 10 + a.get(words[2], -1)
    
    if 100 <= num <= 999:
        b = num
        c = num
        while not f(b) and not f(c):
            b -= 1
            c += 1
        
        while not f(b):
            b -= 1
        
        while not f(c):
            c += 1
        
        if f(b):
            print(b)
        else:
            print(c)
    else:
        print("wrong input")
